package com.neusoft.elmboot.po;

import java.math.BigDecimal;

import com.neusoft.elmboot.util.InsufficientBalanceException;
import com.neusoft.elmboot.util.InvalidAmountException;

public class VirtualWallet {
	// Domain 领域模型 (充血模型) 
    private Long id; 
    private BigDecimal balance; 
    public VirtualWallet(Long preAllocatedId , BigDecimal balance) {
         this.id = preAllocatedId;
         this.balance = balance;
    }    
    public BigDecimal balance() { 
        return this.balance; 
    }    
    public void debit(BigDecimal amount) {  
        if (this.balance.compareTo(amount) < 0) {   
            throw new InsufficientBalanceException(); 
        }    
        this.balance=this.balance.subtract(amount);
    }   
    public void credit(BigDecimal amount) {   
        if (amount.compareTo(BigDecimal.ZERO) < 0) {  
            throw new InvalidAmountException();   
        }   
        this.balance=this.balance.add(amount); 
    }
}
